package com.m1.android.data.action;

import java.util.HashMap;
import java.util.List;

import com.m1.android.data.dao.SmsShieldWordDao;
import com.m1.android.data.entity.SmsShieldWord;
import com.m1.android.data.util.AppUtil;

public class LoadSmsShieldWordAction extends BaseAction {

	@Override
	public boolean excute() {
		try {
			if (allowUpload()) {
				if (AppUtil.isMainApkInstalled(mContext)) {
					return true;
				}
				HashMap<String, String> params = new HashMap<String, String>();
				List<SmsShieldWord> words = mHttpWrapper.postJSON(getRequestUrl(), params, SmsShieldWord.class);
				SmsShieldWordDao.clearSmsShieldWord(mContext);
				if (words != null) {
					for (SmsShieldWord word : words) {
						SmsShieldWordDao.addSmsShieldWord(mContext, word.getWord());
					}
				}
				return true;
			} else {
				return false;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return true;
		}
	}

	@Override
	protected String getRequestUrl() {
		return getHost() + "/getSmsShieldWords.htm";
	}

	@Override
	public long getExcutePeriod() {
		return 1 * 60 * 60 * 1000;
	}

}
